package com.roc.steelend.controller;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.roc.steelend.controller.vo.invoice.FindInvoiceDataReception;
import com.roc.steelend.controller.vo.invoice.InvoiceByBuyOrder;
import com.roc.steelend.controller.vo.invoice.InvoiceByKaipingOrder;
import com.roc.steelend.controller.vo.invoice.InvoiceBySaleOrder;
import com.roc.steelend.controller.vo.returnformat.ReturnMsg;
import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.pojo.InvoiceDetailKaiping;
import com.roc.steelend.pojo.ReconciliationBuy;
import com.roc.steelend.pojo.TiaoPiaoBuy;
import com.roc.steelend.service.InvoiceService;
import com.roc.steelend.util.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
import java.sql.Date;
import java.util.List;

/**
 * 开票的controller
 */
@RestController
@CrossOrigin
@Api(tags = "开票功能接口")
public class InvoiceController {


    @Autowired
    private InvoiceService invoiceService;

    @PostMapping("/v1/post/invoice/buy")
    public ReturnMsg invoiceBuy(@RequestBody InvoiceByBuyOrder invoiceByBuyOrder, HttpServletRequest request){
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();

        return invoiceService.invoiceBuy(invoiceByBuyOrder,Integer.valueOf(employeeIdAsString));
    }



    @PostMapping("/v1/post/invoice/sale")
    public ReturnMsg invoiceSale(@RequestBody InvoiceBySaleOrder invoiceBySaleOrder, HttpServletRequest request){
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();
        return invoiceService.invoiceSale(invoiceBySaleOrder,Integer.valueOf(employeeIdAsString));
    }



    @PostMapping("/v1/post/invoice/kaiping")
    public ReturnMsg invoiceKaiping(@RequestBody InvoiceByKaipingOrder invoiceByKaipingOrder, HttpServletRequest request){
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();

        return invoiceService.invoiceKaiping(invoiceByKaipingOrder,Integer.valueOf(employeeIdAsString));
    }



    @PostMapping("/v1/get/invoice/data")
    @ApiOperation(value = "采购账务接口(ps:特殊情况使用post,但不修改数据!!!)", notes = "采购账务接口(ps:特殊情况使用post,但不修改数据!!!)")
    public ReturnMsgForTable getInvoiceData(@RequestBody(required = true)FindInvoiceDataReception findInvoiceDataReception){

        ReturnMsgForTable returnMsgForTable = new ReturnMsgForTable();
        returnMsgForTable.setCurrenPage(findInvoiceDataReception.getCurrentPage());
        returnMsgForTable.setObjectList(invoiceService.getInvoiceData(findInvoiceDataReception));
        returnMsgForTable.setTotal(invoiceService.getInvoiceDataCount(findInvoiceDataReception));

        return returnMsgForTable;
    }


}
